home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / Tools / Development / TinyGL / ami / content / ad709 / tinygl / src / init.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-08-15  |  4.4 KB  |  200 lines

  1. /*$T init.c GC 1.137 08/09/02 17:47:18 */
  2.  
  3. /*$6
  4.  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  5.  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  6.  */
  7.  
  8. #include "zgl.h"
  9.  
  10. GLContext    *gl_ctx;
  11.  
  12. /* */
  13.  
  14. void initSharedState(GLContext *c) {
  15.     GLSharedState    *s = &c->shared_state;
  16.     /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
  17.  
  18.     s->lists = calloc(1, sizeof(GLList *) * MAX_DISPLAY_LISTS);
  19.     s->texture_hash_table = calloc(1, sizeof(GLTexture *) * TEXTURE_HASH_TABLE_SIZE);
  20.  
  21.     alloc_texture(c, 0);
  22. }
  23.  
  24. /* */
  25. void endSharedState(GLContext *c) {
  26.     GLSharedState    *s = &c->shared_state;
  27.     int                i;
  28.     /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
  29.  
  30.     for(i = 0; i < MAX_DISPLAY_LISTS; i++) {
  31.         /* TODO */
  32.     }
  33.  
  34.     free(s->lists);
  35.     free(s->texture_hash_table);
  36. }
  37.  
  38. /* */
  39. void glInit(void *zbuffer1) {
  40.     ZBuffer        *zbuffer = (ZBuffer *) zbuffer1;
  41.     GLContext    *c;
  42.     GLViewport    *v;
  43.     int            i;
  44.  
  45.     c = calloc(1, sizeof(GLContext));
  46.     gl_ctx = c;
  47.  
  48.     c->zb = zbuffer;
  49.  
  50.     /* allocate GLVertex array */
  51.     c->vertex_max = POLYGON_MAX_VERTEX;
  52.     c->vertex = malloc(POLYGON_MAX_VERTEX * sizeof(GLVertex));
  53.  
  54.     /* viewport */
  55.     v = &c->viewport;
  56.     v->xmin = 0;
  57.     v->ymin = 0;
  58.     v->xsize = zbuffer->xsize;
  59.     v->ysize = zbuffer->ysize;
  60.     v->updated = 1;
  61.  
  62.     /* shared state */
  63.     initSharedState(c);
  64.  
  65.     /* lists */
  66.     c->exec_flag = 1;
  67.     c->compile_flag = 0;
  68.     c->print_flag = 0;
  69.  
  70.     c->in_begin = 0;
  71.  
  72.     /* lights */
  73.     for(i = 0; i < MAX_LIGHTS; i++) {
  74.         GLLight *l = &c->lights[i];
  75.         l->ambient = gl_V4_New(0, 0, 0, 1);
  76.         l->diffuse = gl_V4_New(1, 1, 1, 1);
  77.         l->specular = gl_V4_New(1, 1, 1, 1);
  78.         l->position = gl_V4_New(0, 0, 1, 0);
  79.         l->norm_position = gl_V3_New(0, 0, 1);
  80.         l->spot_direction = gl_V3_New(0, 0, -1);
  81.         l->norm_spot_direction = gl_V3_New(0, 0, -1);
  82.         l->spot_exponent = 0;
  83.         l->spot_cutoff = 180;
  84.         l->attenuation[0] = 1;
  85.         l->attenuation[1] = 0;
  86.         l->attenuation[2] = 0;
  87.         l->enabled = 0;
  88.     }
  89.  
  90.     c->first_light = NULL;
  91.     c->ambient_light_model = gl_V4_New(0.2, 0.2, 0.2, 1);
  92.     c->local_light_model = 0;
  93.     c->lighting_enabled = 0;
  94.     c->light_model_two_side = 0;
  95.  
  96.     /* default materials */
  97.     for(i = 0; i < 2; i++) {
  98.         GLMaterial    *m = &c->materials[i];
  99.         m->emission = gl_V4_New(0, 0, 0, 1);
  100.         m->ambient = gl_V4_New(0.2, 0.2, 0.2, 1);
  101.         m->diffuse = gl_V4_New(0.8, 0.8, 0.8, 1);
  102.         m->specular = gl_V4_New(0, 0, 0, 1);
  103.         m->shininess = 0;
  104.     }
  105.  
  106.     c->current_color_material_mode = GL_FRONT_AND_BACK;
  107.     c->current_color_material_type = GL_AMBIENT_AND_DIFFUSE;
  108.     c->color_material_enabled = 0;
  109.  
  110.     /* textures */
  111.     glInitTextures(c);
  112.  
  113.     /* default state */
  114.     c->current_color.X = 1.0;
  115.     c->current_color.Y = 1.0;
  116.     c->current_color.Z = 1.0;
  117.     c->current_color.W = 1.0;
  118.     c->longcurrent_color[0] = 65535;
  119.     c->longcurrent_color[1] = 65535;
  120.     c->longcurrent_color[2] = 65535;
  121.  
  122.     c->current_normal.X = 1.0;
  123.     c->current_normal.Y = 0.0;
  124.     c->current_normal.Z = 0.0;
  125.     c->current_normal.W = 0.0;
  126.  
  127.     c->current_edge_flag = 1;
  128.  
  129.     c->current_tex_coord.X = 0;
  130.     c->current_tex_coord.Y = 0;
  131.     c->current_tex_coord.Z = 0;
  132.     c->current_tex_coord.W = 1;
  133.  
  134.     c->polygon_mode_front = GL_FILL;
  135.     c->polygon_mode_back = GL_FILL;
  136.  
  137.     c->current_front_face = 0;    /* 0 = GL_CCW 1 = GL_CW */
  138.     c->current_cull_face = GL_BACK;
  139.     c->current_shade_model = GL_SMOOTH;
  140.     c->cull_face_enabled = 0;
  141.     c->blending_enabled = 0;
  142.  
  143.     /* clear */
  144.     c->clear_color.v[0] = 0;
  145.     c->clear_color.v[1] = 0;
  146.     c->clear_color.v[2] = 0;
  147.     c->clear_color.v[3] = 0;
  148.     c->clear_depth = 0;
  149.  
  150.     /* selection */
  151.     c->render_mode = GL_RENDER;
  152.     c->select_buffer = NULL;
  153.     c->name_stack_size = 0;
  154.  
  155.     /* matrix */
  156.     c->matrix_mode = 0;
  157.  
  158.     c->matrix_stack_depth_max[0] = MAX_MODELVIEW_STACK_DEPTH;
  159.     c->matrix_stack_depth_max[1] = MAX_PROJECTION_STACK_DEPTH;
  160.     c->matrix_stack_depth_max[2] = MAX_TEXTURE_STACK_DEPTH;
  161.  
  162.     for(i = 0; i < 3; i++) {
  163.         c->matrix_stack[i] = calloc(1, c->matrix_stack_depth_max[i] * sizeof(M4));
  164.         c->matrix_stack_ptr[i] = c->matrix_stack[i];
  165.     }
  166.  
  167.     glMatrixMode(GL_PROJECTION);
  168.     glLoadIdentity();
  169.     glMatrixMode(GL_TEXTURE);
  170.     glLoadIdentity();
  171.     glMatrixMode(GL_MODELVIEW);
  172.     glLoadIdentity();
  173.  
  174.     c->matrix_model_projection_updated = 1;
  175.  
  176.     /* opengl 1.1 arrays */
  177.     c->client_states = 0;
  178.  
  179.     /* opengl 1.1 polygon offset */
  180.     c->offset_states = 0;
  181.  
  182.     /* clear the resize callback function pointer */
  183.     c->gl_resize_viewport = NULL;
  184.  
  185.     /* specular buffer */
  186.     c->specbuf_first = NULL;
  187.     c->specbuf_used_counter = 0;
  188.     c->specbuf_num_buffers = 0;
  189.  
  190.     /* depth test */
  191.     c->depth_test = 0;
  192. }
  193.  
  194. /* */
  195. void glClose(void) {
  196.     GLContext    *c = gl_get_context();
  197.     endSharedState(c);
  198.     free(c);
  199. }
  200.